package yxy.game.pm2.bean.pubsub;

import yxy.apple.util.PubSub.ISubscription;
import yxy.apple.util.PubSub.Publisher;
import yxy.apple.util.concurrent.ThreadPoolManager;
import yxy.game.pm2.bean.Hero;

/** 武将状态发布 */
public class HeroPublisher extends Publisher {
	static private HeroPublisher instance;

	public static HeroPublisher getInstance() {
		if (instance == null) {
			instance = new HeroPublisher();
		}
		return instance;
	}

	private HeroPublisher() {

	}

	public void publish(String playerCode, Hero hero) {
		Runnable run = () -> {
			try {
				this.publish(new HeroSubscription(playerCode, hero));
			} catch (Exception e) {
				e.printStackTrace();
			}
		};
		ThreadPoolManager.getInstance().execute(run);
	}

	public static class HeroSubscription implements ISubscription {
		private String playerCode;
		private Hero hero;

		public HeroSubscription(String playerCode, Hero hero) {
			this.playerCode = playerCode;
			this.hero = hero;
		}

		public String getPlayerCode() {
			return playerCode;
		}

		public Hero getHero() {
			return hero;
		}
	}
}
